home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / UTILITY / DO1002.ARJ / GOSUB.SCR < prev    next >
Text File  |  1991-12-29  |  2KB  |  64 lines

  1. .pg wi full clr cy
  2.     COMMAND NAME»gray«: »%t« GosubLabel »ye«
  3.  
  4.     /GOSUB {Label} [{param1} {param2} ... ]
  5. /cw
  6.     The »%t«GosubLabel»#« command executes a section of the script
  7.     until a »%t«ReturnfromSub»#« command is found. It then returns
  8.     execution to the line after the »%t«GosubLabel»#« Command.
  9.  
  10.     The »%t«GosubLabel»#« is similar to the »%t«GotoLabel»#« command except
  11.     that execution continues until a »%t«ReturnfromSub»#« command is
  12.     found. Then the program returns to the line after the
  13.     »%t«GosubLabel»#« command.
  14.  
  15. .pg clr
  16.     »%t«GosubLabel»#« commands can be nested »ye«10»#« deep.
  17.  
  18.     »wh«{Label}»#«             The label defining the start of the
  19.                         executed portion of the script.
  20.                         Variables in »cy«{Label}»#« are expanded.
  21.                         »wh«Labels are evaluated in upper case»#«.
  22.     »wh«{params}»#«            Parameters which are passed to the subroutine.
  23.                         These parameters are like those passed to
  24.                         scripts by the »%t«ExecScript»#« command.  They are
  25.                         named »ye«{Label}01»#«, »ye«{Label}02»#«, etc.  Parameters
  26.                         are »re«deleted»#« when the »%t«ReturnFromSub»#« command is
  27.                         executed.
  28.  
  29. .pg clr
  30.     Here is an example of a calculator implemented as a
  31.     »%t«GosubLabel»#« routine. Enter a pair of numbers separated by a
  32.     »wh«<space>»#« to be multiplied. Press »bo«<enter>»#« to execute each
  33.     command after it is displayed.
  34.  
  35. .pg
  36. ┌──────────────────────────┐
  37. │ »%t«/GOSUB»ye« Parameter Passing»#« │
  38. └──────────────────────────┘
  39.  
  40. :TOP
  41. /SET default ""
  42. Enter two numbers separated by a space or
  43. press »bo«<enter>»#« to stop demonstration.
  44. /GETS Numbers Default "Enter two numbers:" 40 UC
  45. /IF %numbers NE "" END
  46. /SET P @pos(%numbers,' ')
  47. /SET num1 @cpy(%numbers,1,%p-1)
  48. /SET num2 @cpy(%numbers,%p+1,254)
  49. |/GOSUB Compute %num1 %num2
  50. /GOTO TOP
  51. :Compute
  52.  
  53. The subroutine will compute the two numbers and display the
  54. result.
  55. |/MATH Result "%compute01 * %compute02"
  56. The Result is »bo« %result »#«
  57. /RETURN
  58. :end
  59. .clr
  60.     »gr«NOTE»wh«:»#« If you wish to save parameters passed to a sub-routine
  61.     for use outside the sub-routine, you »re«must»#« move them to
  62.     permanent variables before the »%t«ReturnFromSub»#« command is executed.
  63. /ENDEXEC CLEAR
  64.